package game;

import java.util.ArrayList;
import java.util.Collections;

public class Deck {
	
	ArrayList<Card> cards;
	
	// TODO: as cards are added to the deck, number them and make this number available with getUniqueName()
	
	public Deck(CardName[] cardNames, int[] quantities) {
		
		if (cardNames.length != quantities.length) {
			throw new RuntimeException("invalid deck!");
		}		
		cards = new ArrayList<Card>();
				
		for (int i = 0; i < cardNames.length; i++) {
			for (int j = 0; j < quantities[i]; j++) {
				Card c = CardFactory.makeCard(cardNames[i]);
				cards.add(c);								
			}
		}
		this.shuffle();
	}
	
	public void shuffle() {
		Collections.shuffle(cards);
	}

	public Card draw() {
		Card c = cards.get(0);
		cards.remove(0);
		return c;
	}

	public Card getCardFromDeck(String string) {
		for (int i = 0; i < cards.size(); i++) {
			Card c = cards.get(i);
			if (c.getName().equals(string)) {
				cards.remove(i);
				return c;
			}
		}
		return null; // no card left in deck
	}

}
